

package tpcar.ejb;

//import java.util.ArrayList;
//import java.util.Collection;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;


/**
 * a card.
 */
@Entity
@NamedQueries({@NamedQuery(name="allCV", query="select o FROM CarteDeVisite o"),
               @NamedQuery(name="findByName", query="select o FROM CarteDeVisite o WHERE o.personne.nom = :nom")
              }
             )
/*
@NamedQueries({@NamedQuery(name="allCV", query="select o FROM CarteDeVisite o"),
               @NamedQuery(name="findByName", query="select o FROM CarteDeVisite o WHERE nom = :nom"),
               @NamedQuery(name="findByPrefix", query="select o FROM CarteDeVisite o WHERE nom LIKE CONCAT(:nom,'%')")
              }
             )

*/


// SELECT x FROM Magazine x WHERE x.title LIKE 'J%'
//@NamedQuery(name = "allAuthors", query = "select o FROM Author o")
//DELETE s FROM Subscription s WHERE s.subscriptionDate < :today
               
public class CarteDeVisite implements java.io.Serializable{

    /**
	 * 
	 */
	private static final long serialVersionUID = 1981959009624228041L;

	/**
     * Primary key (will be auto generated).
     */
    private long id;
		
		/**
     * email of the card's holder.
     */
		private String email = null;
		
		/**
     * Phone of the card's holder.
     */
		private String phone = null;
		
		private Personne personne = null;
		
    /**
     * Default constructor.
     */
    public CarteDeVisite() {
        
    }

    /**
     * Constructor with a given card.
     * @param nom - the firsname of the card's holder
     * @param prenom - the lastname of the card's holder
     * @param email - the email of the card's holder
     * @param phone - the phone of the card's holder
     */
    public CarteDeVisite(final Personne personne, final String email, final String phone) {
        this();
        this.email = email;
        this.phone = phone;
        this.personne=personne;
    }

  /**
     * @return firstname of the card's holder
     */
    public String getPrenom() {
        return personne.getPrenom();
    }

    /**
	@return lastname of the card's holder
     */
    public String getNom() {
        return personne.getNom();
    }

  /**
     * @return email of the card's holder
     */
    public String getEmail() {
        return email;
    }

    /**
     * Sets the email of the card's holder.
     * @param email - the email of this card's holder
     */
    public void setEmail(final String email) {
        this.email = email;
    }

  /**
     * @return phone of the card's holder
     */
    public String getPhone() {
        return phone;
    }

    /**
     * Sets the phone of the card's holder.
     * @param phone - the phone of the card's holder
     */
    public void setPhone(final String phone) {
        this.phone = phone;
    }
    /**
     * @return an id for this object (incremented automatically)
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="Identifiant")
    public long getId() {
        return this.id;
    }

    /**
     * Sets the id of this author object.
     * @param id the given id of this author
     */
    public void setId(final long id) {
        this.id = id;
    }


    /**
     * @return String representation of this entity object.
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder(this.getClass().getName());
        sb.append("[id=");
        sb.append(getId());
        sb.append(", nom=");
        sb.append(getNom());
        sb.append(", prenom=");
        sb.append(getPrenom());  
        sb.append(", email=");
        sb.append(getEmail()); 
        sb.append(", phone=");
        sb.append(getPhone());     
        sb.append("]");
        return sb.toString();
    }
    
	 @ManyToOne
	 @JoinColumns({
		 	@JoinColumn(name="nom_personne", referencedColumnName="nompersonne"),
		 	@JoinColumn(name="prenom_personne", referencedColumnName="prenompersonne")
	 })
	 
	 public Personne getPersonne()
	 {
		 return personne;
	 }
	 
	 public void setPersonne(Personne p)
	 {
		this.personne=p; 
	 }
}
